package com.gientech.springRocketmq.redisController;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;


import java.nio.charset.StandardCharsets;

@RestController
public class ProviderController {

    @GetMapping("/test/01")
    public void syncMethod1() throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer("producer-luxiaoyu");
        producer.setNamesrvAddr("172.0.0.1:9876");
        producer.start();
        for (int i = 0; i < 11; i++) {
            Message message = new Message("TopicMessage", "Message_Tag", ("Hello RocketMq [" + i + " ]").getBytes(StandardCharsets.UTF_8));
            SendResult sendResult = producer.send(message);
           System.out.printf("%s%n", sendResult);
        }
        producer.shutdown();
    }
}
